package android.slc.module.sys.ui.dict.type

import android.slc.appbase.ui.AppView
import android.slc.appbase.ui.widget.grid.GridPaneUtils
import android.slc.appbase.ui.widget.spinner.SpinnerNumberWrapper
import android.slc.appdb.sys.enums.EnableEnum
import android.slc.appdb.utils.DictEnumUtils
import android.slc.box.commonlibrary.compat.SlcResourceUtils
import android.slc.box.core.property.DataChangeListener
import android.slc.box.core.utils.ViewUtils
import javafx.beans.InvalidationListener
import javafx.fxml.FXML
import javafx.scene.control.Button
import javafx.scene.control.ComboBox
import javafx.scene.control.Spinner
import javafx.scene.control.TextField
import javafx.scene.layout.GridPane
import javafx.scene.layout.VBox

class DictTypeEditView : AppView<DictTypeEditVm>() {

    @FXML
    lateinit var propertyParentPane: GridPane

    @FXML
    lateinit var etDictName: TextField

    @FXML
    lateinit var etDictType: TextField

    override fun onBindView() {
        super.onBindView()
        this.requireWindow().title = SlcResourceUtils.getString("app_label_dict_type_add")
        GridPaneUtils.formatGridColumn(propertyParentPane, 1)
        this.etDictName.textProperty().bindBidirectional(viewModel.dictNameProperty)
        this.etDictType.textProperty().bindBidirectional(viewModel.dictTypeProperty)
        DictTypeEditVd(boxContentPane, propertyParentPane, viewModel).initView()
    }

    override fun onRegisterLiveEvent() {
        super.onRegisterLiveEvent()
        this.viewModel.isEditProperty.addListener(DataChangeListener {
            if (this.viewModel.isEditProperty.value) {
                this.etDictType.isDisable =
                    !EnableEnum.getEnableByValue(this.viewModel.editDictTypeStatusProperty.value)
                this.requireWindow().title = SlcResourceUtils.getString("app_label_dict_type_edit")
            } else {
                this.requireWindow().title = SlcResourceUtils.getString("app_label_dict_type_add")
            }
        })
    }

    override fun onBindViewLater() {
        super.onBindViewLater()
        this.viewModel.initVm()
    }
}